document.addEventListener('DOMContentLoaded', function() {
    // 搜索功能
    const searchInput = document.querySelector('.search-bar input');
    const searchButton = document.querySelector('.search-bar button');

    searchButton.addEventListener('click', function() {
        const searchTerm = searchInput.value.trim();
        if (searchTerm) {
            // 跳转到餐厅列表页面并带上搜索参数
            window.location.href = `pages/restaurants.html?search=${encodeURIComponent(searchTerm)}`;
        }
    });

    // 回车键搜索
    searchInput.addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            searchButton.click();
        }
    });

    // 餐厅卡片点击事件
    const restaurantCards = document.querySelectorAll('.restaurant-card');
    restaurantCards.forEach(card => {
        card.addEventListener('click', function() {
            const restaurantName = this.querySelector('.restaurant-name').textContent;
            // 跳转到餐厅详情页
            window.location.href = `pages/restaurant-detail.html?name=${encodeURIComponent(restaurantName)}`;
        });
    });

    // 分类卡片点击事件
    const categoryCards = document.querySelectorAll('.category-card');
    categoryCards.forEach(card => {
        card.addEventListener('click', function() {
            const categoryName = this.querySelector('h3').textContent;
            // 跳转到餐厅列表页面并带上分类参数
            window.location.href = `pages/restaurants.html?category=${encodeURIComponent(categoryName)}`;
        });
    });
});
